package com.kindergarten.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kindergarten.pojo.Children;
import com.kindergarten.pojo.Classes;
import com.kindergarten.pojo.Systemlog;
import com.kindergarten.service.ISystemlogService;
import com.kindergarten.utils.MMGridPageVoBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bruce
 * @since 2022-11-04
 */
@Controller
@RequestMapping("/systemlog-api")
public class SystemlogController {

    @Autowired
    ISystemlogService systemLogService;

    /**
     * 01-跳转到模板引擎页面
     * @return
     */
    @GetMapping("topage")
    @Secured(value = {"ROLE_超级管理员"})
    public String topage(Model model) {
        return "systemLog";
    }

    /**
     * 02-数据加载分页
     * @return
     */
    @ResponseBody
    @RequestMapping("page")
    @Secured(value = {"ROLE_超级管理员"})
    public MMGridPageVoBean page(Systemlog systemlog) {

        MMGridPageVoBean pageVoBean = new MMGridPageVoBean();

        QueryWrapper<Systemlog> queryWrapper = new QueryWrapper<Systemlog>();
        queryWrapper.orderByDesc("createtime");

        queryWrapper.eq(systemlog.getLogtype() != null && !"-1".equals(systemlog.getLogtype().toString()), "logtype", systemlog.getLogtype());

        IPage<Systemlog> page = systemLogService.page(new Page<Systemlog>(systemlog.getPage(), systemlog.getLimit()), queryWrapper);

        List<Systemlog> records = page.getRecords();

        pageVoBean.setRows(records); //每页数据
        pageVoBean.setTotal(page.getTotal()); //总条数
        return pageVoBean;
    }

}
